from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional

class ClassBase(BaseModel):
    class_code: str = Field(..., description="班级编码（如：20250101）", max_length=20)
    class_name: str = Field(..., description="班级名称（如：一年级一班）", max_length=50)
    academic_year_id: int = Field(..., description="学年ID")
    grade: int = Field(..., description="年级：1-一年级 2-二年级 3-三年级 4-四年级 5-五年级")
    class_no: int = Field(..., description="班级序号：1-10")
    classroom_id: Optional[int] = Field(None, description="教室ID")
    head_teacher_id: Optional[int] = Field(None, description="班主任ID")
    student_count: int = Field(0, description="学生人数")
    status: int = Field(1, description="状态：0-解散 1-正常")

class ClassCreate(ClassBase):
    """创建班级时使用的模型"""
    pass

class ClassUpdate(BaseModel):
    """更新班级时使用的模型"""
    class_code: Optional[str] = None
    class_name: Optional[str] = None
    academic_year_id: Optional[int] = None
    grade: Optional[int] = None
    class_no: Optional[int] = None
    classroom_id: Optional[int] = None
    head_teacher_id: Optional[int] = None
    student_count: Optional[int] = None
    status: Optional[int] = None

class Class(ClassBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True